import 'dart:convert';

import 'package:flutter/services.dart' show rootBundle;
import 'package:get/get.dart';
import 'package:xin_nuo_pda/bean/IndexBean.dart';
import 'package:xin_nuo_pda/values/constant.dart';

class IndexController extends GetxController {
   List<IndexBean> productList = <IndexBean>[];
   List<IndexBean> eqpList = <IndexBean>[];
   List<IndexBean> qaList = <IndexBean>[];
   List<IndexBean> tmtList = <IndexBean>[];

   @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    productList.clear();
    eqpList.clear();
    qaList.clear();
    tmtList.clear();
    loadAsset();
  }
  void loadAsset() async {
    var productJson = await rootBundle.loadString('assets/files/product.txt');
    var productJsonList = jsonDecode(productJson);
    List<Map<String, dynamic>> productListMap =
        new List<Map<String, dynamic>>.from(productJsonList);
    productListMap.forEach((element) {
      var indexBean = IndexBean.fromJson(element);
      if(AUTHList.contains(indexBean.text)){
        productList.add(indexBean);
      }
    });

    var eqpJson = await rootBundle.loadString('assets/files/eqp.txt');
    var eqpJsonList = jsonDecode(eqpJson);
    List<Map<String, dynamic>> eqpListMap =
    new List<Map<String, dynamic>>.from(eqpJsonList);
    eqpListMap.forEach((element) {
      var indexBean = IndexBean.fromJson(element);
      if(AUTHList.contains(indexBean.text)){
        eqpList.add(indexBean);
      }
      // eqpList.add(IndexBean.fromJson(element));
    });

    var qaJson = await rootBundle.loadString('assets/files/qa.txt');
    var qaJsonList = jsonDecode(qaJson);
    List<Map<String, dynamic>> qaListMap =
    new List<Map<String, dynamic>>.from(qaJsonList);
    qaListMap.forEach((element) {
      var indexBean = IndexBean.fromJson(element);
      if(AUTHList.contains(indexBean.text)){
        qaList.add(indexBean);
      }
      // qaList.add(IndexBean.fromJson(element));
    });

    var tmtJson = await rootBundle.loadString('assets/files/tmt.txt');
    var tmtJsonList = jsonDecode(tmtJson);
    List<Map<String, dynamic>> tmtListMap =
    new List<Map<String, dynamic>>.from(tmtJsonList);
    tmtListMap.forEach((element) {
      var indexBean = IndexBean.fromJson(element);
      if(AUTHList.contains(indexBean.text)){
        tmtList.add(indexBean);
      }
      // tmtList.add(IndexBean.fromJson(element));
    });
    update();
  }

}
